import { createStore } from 'vuex'

export default createStore({
  state() {
    return {
      user:window.localStorage.getItem('user'),
        // window.localStorage.getItem('user' || '[]') == null
        //   ? ''
        //   : window.localStorage.getItem('user' || '[]'),
      userType: '',
    }
  },
  mutations: {
    login(state, payload) {
      state.user = payload.user
      state.userType = payload.userType
      console.log('user ' + state.user)
      console.log('userType ' + state.userType)
      window.localStorage.setItem('user', JSON.stringify(payload.user))
      window.localStorage.setItem('userType', payload.userType)
    }
  },
  getters: {
    getUser(state) {
      return JSON.parse(state.user).account
    },
  },
})
